home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SGI Developer Toolbox 6.1
/
SGI Developer Toolbox 6.1 - Disc 4.iso
/
public
/
SciAn
/
src
/
ScianCurrentFunctions.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-08-01
|
9KB
|
361 lines
/*ScianCurrentFunctions.c
Eric Pepke
10 August 1993
Does current functions, i.e., functions that work on individual windows' current objects.
*/
#include "Scian.h"
#include "ScianTypes.h"
#include "ScianLists.h"
#include "ScianWindows.h"
#include "ScianColors.h"
#include "ScianIDs.h"
#include "ScianObjWindows.h"
#include "ScianButtons.h"
#include "ScianErrors.h"
#include "ScianDraw.h"
#include "ScianControls.h"
#include "ScianArrays.h"
#include "ScianScripts.h"
#include "ScianVisWindows.h"
#include "ScianIcons.h"
#include "ScianEvents.h"
#include "ScianStyle.h"
#include "ScianCurrentFunctions.h"
#include "ScianHelp.h"
#include "ScianFilters.h"
#include "ScianFileSystem.h"
#include "ScianSockets.h"
#include "ScianPointers.h"
#include "ScianMenus.h"
#include "ScianPreferences.h"
#include "ScianFileSystem.h"
#include "ScianAnimation.h"
#include "ScianSymbols.h"
ObjPtr currentActionClass;
typedef struct
{
char *name; /*Name of function*/
NameTyp message; /*Message to send to object*/
char *buttonHelp; /*Button help*/
char *menuHelp; /*Menu help*/
char *scriptLine; /*Line for script*/
ObjPtr menu; /*Which menu this routine is in*/
int menuGroup; /*Which menu group this function is in*/
} CurrentFunction;
int nCurrentFunctions = 0; /*# of current functions*/
static CurrentFunction *currentFunctions;
#ifdef PROTO
int NameToCurrentFunction(char *name)
#else
int NameToCurrentFunction(name)
char *name;
#endif
/*Converts a name to a function number, or -1*/
{
int funcNum;
/*Search for the named function*/
for (funcNum = 0; funcNum < nCurrentFunctions; ++funcNum)
{
if (0 == strcmp2(name, currentFunctions[funcNum] . name))
{
break;
}
}
if (funcNum >= nCurrentFunctions)
{
/*Not found, too bad.*/
char nameStr[300];
sprintf(nameStr, "Internal error: name '%s' not found", name);
ReportError("NameToCurrentFunction", nameStr);
return -1;
}
return funcNum;
}
#ifdef PROTO
Bool CurrentFunctionScriptLine(char *line)
#else
Bool CurrentFunctionScriptLine(line)
char *line;
#endif
/*If s is a script line, finds out if it is a valid script line for a
current function. If so, does it and returns true, otherwise does nothing
and returns false. Determines whether it is valid by matching the
script line*/
{
int funcNum;
register char *s, *p, *t;
/*For all possible functions*/
for (funcNum = 0; funcNum < nCurrentFunctions; ++funcNum)
{
/*Try to match script line against script*/
s = line;
p = currentFunctions[funcNum] . scriptLine;
if (!p) continue;
SKIPBLANKS(s);
SKIPBLANKS(p);
while (*p)
{
if (isspace(*p))
{
SKIPBLANKS(s);
SKIPBLANKS(p);
}
else if (toupper(*p) != toupper(*s))
{
/*Failure to match*/
break;
}
else
{
++s;
++p;
}
}
if (*p == 0)
{
ObjPtr list;
ThingListPtr runner;
ObjPtr object;
/*It's a match! Do this function and return true*/
Log(currentFunctions[funcNum] . scriptLine);
Log("\n");
object = GetVar((ObjPtr) selWinInfo, CURRENT);
if (object)
{
DeferMessage(object, currentFunctions[funcNum] . message);
}
return true;
}
}
return false;
}
#ifdef PROTO
void DefineCurrentFunction(char *funcName, NameTyp message,
char *scriptLine,
char *buttonHelp,
char *menuHelp, ObjPtr menu, int menuGroup)
#else
void DefineCurrentFunction(funcName, message, scriptLine,
buttonHelp, menuHelp, menu, menuGroup)
char *funcName;
NameTyp message;
char *scriptLine;
char *buttonHelp;
char *menuHelp;
ObjPtr menu;
int menuGroup;
#endif
/*Defines a current function
funcName is the name of the function for the menu and buttons
message is a message to do it
scriptLine is the script line
buttonHelp is the help string for a button, or nothing for no button
menuHelp is the help string for a menu
menu is which menu to use, or NULLOBJ for none
menuGroup is the menu group
*/
{
if (nCurrentFunctions)
{
currentFunctions = Realloc(currentFunctions, (nCurrentFunctions + 1) * sizeof(CurrentFunction));
}
else
{
currentFunctions = Alloc((nCurrentFunctions + 1) * sizeof(CurrentFunction));
}
if (funcName)
{
currentFunctions[nCurrentFunctions] . name = Alloc(strlen(funcName) + 1);
strcpy(currentFunctions[nCurrentFunctions] . name, funcName);
}
else
{
currentFunctions[nCurrentFunctions] . name = (char *) 0;
}
currentFunctions[nCurrentFunctions] . message = message;
currentFunctions[nCurrentFunctions] . menu = menu;
currentFunctions[nCurrentFunctions] . menuGroup = menuGroup;
if (scriptLine)
{
currentFunctions[nCurrentFunctions] . scriptLine = Alloc(strlen(scriptLine) + 1);
strcpy(currentFunctions[nCurrentFunctions] . scriptLine, scriptLine);
}
else
{
currentFunctions[nCurrentFunctions] . scriptLine = (char *) 0;
}
if (buttonHelp)
{
currentFunctions[nCurrentFunctions] . buttonHelp = Alloc(strlen(buttonHelp) + 1);
strcpy(currentFunctions[nCurrentFunctions] . buttonHelp, buttonHelp);
}
else
{
currentFunctions[nCurrentFunctions] . buttonHelp = (char *) 0;
}
if (menuHelp)
{
currentFunctions[nCurrentFunctions] . menuHelp = Alloc(strlen(menuHelp) + 1);
strcpy(currentFunctions[nCurrentFunctions] . menuHelp, menuHelp);
}
else
{
currentFunctions[nCurrentFunctions] . menuHelp = (char *) 0;
}
/*Put it on the appropriate menu*/
if (menu)
{
/*Put it on menu*/
ObjPtr action;
action = NewAction(funcName, currentActionClass);
SetVar(action, HELPSTRING, NewString(menuHelp));
AddMenuItem(menu, action, menuGroup);
}
++nCurrentFunctions;
}
ObjPtr CurrentAction(action)
ObjPtr action;
/*Does the action method of a current action*/
{
int whichFunction;
ObjPtr var;
var = GetVar(action, NAME);
if (var)
{
whichFunction = NameToCurrentFunction(GetString(var));
if (contextHelp)
{
/*Give help on the action*/
ContextHelp(action);
contextHelp = false;
MySetCursor(0);
}
else
{
/*Log it*/
if (currentFunctions[whichFunction] . scriptLine)
{
Log(currentFunctions[whichFunction] . scriptLine);
Log("\n");
}
/*Do it*/
if (selWinInfo)
{
ObjPtr object;
object = GetVar((ObjPtr) selWinInfo, CURRENT);
if (object)
{
DeferMessage(object, currentFunctions[whichFunction] . message);
}
}
}
}
return ObjTrue;
}
static ObjPtr MakeCurrentActionActivated(action)
ObjPtr action;
/*Makes a current action activated*/
{
ObjPtr allSelected;
ThingListPtr runner;
int f;
ObjPtr var;
var = GetStringVar("MakeCurrentActionActivated", action, NAME);
if (!var) return ObjFalse;
f = NameToCurrentFunction(GetString(var));
if (f < 0) return ObjFalse;
if (selWinInfo)
{
ObjPtr object;
object = GetVar((ObjPtr) selWinInfo, CURRENT);
if (object && GetMethod(object, currentFunctions[f] . message))
{
SetVar(action, ACTIVATED, ObjTrue);
return ObjTrue;
}
}
SetVar(action, ACTIVATED, ObjFalse);
return ObjTrue;
}
#ifdef PROTO
void InitCurrentFunctions(void)
#else
void InitCurrentFunctions()
#endif
/*Initializes the current function system*/
{
/*Make the class for current actions*/
currentActionClass = NewObject(actionClass, 0L);
AddToReferenceList(currentActionClass);
SetMethod(currentActionClass, ACTIONMETHOD, CurrentAction);
SetVar(currentActionClass, ACTIVATED, ObjFalse);
SetMethod(currentActionClass, ACTIVATED, MakeCurrentActionActivated);
DeclareDependency(currentActionClass, ACTIVATED, READYTOACTIVATE);
/*Define the actions*/
DefineCurrentFunction(CF_CUT, CUT, (char *) 0,
"Pressing this button cuts from the current object and places it on the clipboard.",
"Choosing this menu item cuts from the current object and places it on the clipboard.",
textMenu, 1);
DefineCurrentFunction(CF_COPY, COPY, (char *) 0,
"Pressing this button copies from the current object and places it on the clipboard.",
"Choosing this menu item copies from the current object and places it on the clipboard.",
textMenu, 1);
DefineCurrentFunction(CF_PASTE, PASTE, (char *) 0,
"Pressing this button pastes the contents of the clipboard into the current object.",
"Choosing this menu pastes the contents of the clipboard into the current object.",
textMenu, 1);
}
#ifdef PROTO
void KillCurrentFunctions(void)
#else
void KillCurrentFunctions()
#endif
/*Kills the current function system*/
{
int k;
for (k = 0; k < nCurrentFunctions; ++k)
{
SAFEFREE(currentFunctions[k] . name);
SAFEFREE(currentFunctions[k] . scriptLine);
SAFEFREE(currentFunctions[k] . menuHelp);
SAFEFREE(currentFunctions[k] . buttonHelp);
}
SAFEFREE(currentFunctions);
RemoveFromReferenceList(currentActionClass);
}